package midi;

import inputs.Input;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.Receiver;
import javax.sound.midi.ShortMessage;

import outputAdapters.OutputAdapter;
import outputAdapters.OutputRanges;

public class PitchVelocityMidiOutParameter extends MidiOutParameter {
	private Input pitch;
	private Input velocity;

	public PitchVelocityMidiOutParameter(Input pitch, Input velocity,
			Receiver rec, int channel) {
		super(rec, channel);

		this.pitch = pitch;
		this.velocity = velocity;
	}

	public void Write() {
		int pitchVal = pitch.getValue();
		int velVal = velocity.getValue();

		try {
			ShortMessage msg = new ShortMessage();
			if (pitchVal > 0 && velVal > 0)
				msg.setMessage(ShortMessage.NOTE_ON, channel, pitchVal, velVal);
			else
				msg.setMessage(ShortMessage.NOTE_OFF, channel, 0, 0);

			rec.send(msg, 0);
		} catch (InvalidMidiDataException e) {
		}

	}

}
